package C;

import java.util.ArrayList;
import java.util.Scanner;

public class C17 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        System.out.println(getResult(n,k));
    }
    public static int getResult(int n,int k) {
        int[] fact = new int[n+1];
        fact[1] = 1;
        for (int i=2;i< fact.length;i++) {
            fact[i] = fact[i-1]*i;
        }

        int prefix = 0;
        StringBuffer sb = new StringBuffer();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i=0;i<n+1;i++) {
            list.add(i,i);
        }
        while(n>1) {
            n--;
            int currentFact = fact[n];
            prefix = k/currentFact+(k%currentFact==0?0:1);
            sb.append(list.get(prefix));
            list.remove(prefix);
            k-=(prefix-1)*currentFact;
        }
        sb.append(list.get(1));

        return Integer.parseInt(sb.toString());
    }
}
